package muview;


import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

public class ReturnButton extends Button {

    private String text = "";

    public ReturnButton(Composite parent, int style) {
        super(parent, style);
        addPaintListener(new MyPaintListner());
    }

    @Override
    public String getText() {
        return this.text;
    }

    @Override
    public void setText(String string) {
        this.text = string;
    }

    @Override
    protected void checkSubclass() {

    }

    private class MyPaintListner implements PaintListener {

        public void paintControl(PaintEvent arg0) {
            if (null == getText() || "".equals(getText()))
                return;
            String[] text = getText().split("\n");
            GC gc = arg0.gc;
            for (int i = 0; i < text.length; i++) {
                gc.drawText(text[i], gc.getFontMetrics().getAscent(), 10 + i
                        * gc.getFontMetrics().getHeight(), true);
            }
        }
    }

}